<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 引入vue 和 vue-router -->
    <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.js"></script>
    <script src="https://cdn.bootcss.com/vue-router/3.0.1/vue-router.js"></script>
    <!-- <script src="vue.js"></script> -->
    <!-- <script src="router.js"></script> -->
</head>

<body>
    <div id="app">
        <router-link to="/login/heima">登陆</router-link>
        <router-link to="/register/cz">注册</router-link>

        <router-view></router-view>
    </div>
</body>

</html>
<script>
    // 2.定义login和register组件
    var login = Vue.extend({
        template: "<div>login {{name}}</div>",
        data: function() {
            return {
                name: this.$route.params.name
            }
        }
    })

    var register = Vue.extend({
        template: "<div>register {{name}} {{age}}</div>",
        data: function() {
            return {
                name: this.$route.params.name, //获取name的方法
                age: "注册页面"
            }
        }
    })

    var router = new VueRouter({
        routes: [{
            name: "login",
            path: "/login/:name",
            component: login
        }, {
            name: "register",
            path: "/register/:name",
            component: register
        }]
    })

    new Vue({
        el: "#app",
        data: {

        },
        router: router,
        methods: {

        }
    })
</script>